<?php

$return  = array('code'=>0,'msg'=>'success');
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$fid =  $_G['fid']?:2;
$subject  = $data['subject']?:'无标题';
$message  = '[b]'.$data['message'].'[/b][hr]'?:'';
if($data['img']){
    foreach ($data['img'] as $img){
        $message.= '[img]'.$img.'[/img]';
    }
}

checklowerlimit('post', 0, 1, $fid);

  
	
	$modthread = C::m('forum_thread');
	$bfmethods = $afmethods = array();

	$params = array(
		'subject' => $subject,
		'message' => $message,
		'typeid'  => 0,
		'sortid'  => 0,
		'special' => 0,
	);

	$_GET['save'] = $_G['uid'] ? $_GET['save'] : 0;

	if ($_G['group']['allowsetpublishdate'] && $_GET['cronpublish'] && $_GET['cronpublishdate']) {
		$publishdate = strtotime($_GET['cronpublishdate']);
		if ($publishdate > $_G['timestamp']) {
			$_GET['save'] = 1;
		} else {
			$publishdate = $_G['timestamp'];
		}
	} else {
		$publishdate = $_G['timestamp'];
	}
	$params['publishdate'] = $publishdate;
	$params['save'] = $_GET['save'];

	$params['sticktopic'] = $_GET['sticktopic'];

	$params['digest'] = 0;
	$params['readperm'] = 0;;
	$params['isanonymous'] = 0;
	$params['price'] = 0;

	$params['authorid'] = 1;
	$params['author'] = 'admin';



	$params['typeexpiration'] ='';






	$params['ordertype'] ='';

	$params['hiddenreplies'] ='';

	$params['allownoticeauthor'] = 1;
	$params['tags'] = '';
	$params['bbcodeoff'] = '';
	$params['smileyoff'] = '';
	$params['parseurloff'] ='';
	$params['usesig'] = 1;
	$params['htmlon'] ='';
	if($_G['group']['allowimgcontent']) {
		$params['imgcontent'] = $_GET['imgcontent'];
		$params['imgcontentwidth'] = $_G['setting']['imgcontentwidth'] ? intval($_G['setting']['imgcontentwidth']) : 100;
	}

	$params['geoloc'] = '';

	if($_GET['rushreply']) {
		$bfmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'before_newthread');
		$afmethods[] = array('class' => 'extend_thread_rushreply', 'method' => 'after_newthread');
	}

	$bfmethods[] = array('class' => 'extend_thread_replycredit', 'method' => 'before_newthread');
	$afmethods[] = array('class' => 'extend_thread_replycredit', 'method' => 'after_newthread');

	if($sortid) {
		$bfmethods[] = array('class' => 'extend_thread_sort', 'method' => 'before_newthread');
		$afmethods[] = array('class' => 'extend_thread_sort', 'method' => 'after_newthread');
	}
	$bfmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'before_newthread');
	$afmethods[] = array('class' => 'extend_thread_allowat', 'method' => 'after_newthread');
	$afmethods[] = array('class' => 'extend_thread_image', 'method' => 'after_newthread');

	$modthread->attach_before_methods('newthread', $bfmethods);
	$modthread->attach_after_methods('newthread', $afmethods);
	if($modthread->newthread($params)){
	    returnjson($return);
	}else{
	    $return['code'] = -1;
	    $return['msg'] = 'unknown error';
	    returnjson($return);
	};
	
	









function returnjson($data){
    echo json_encode($data,JSON_UNESCAPED_UNICODE);
    exit;
}


?>